package service

import (
	"mall-api-gin/pkg/Sms"
	"mall-api-gin/pkg/setting"
)

type smsService struct {
	//BaseService
}

var SmsService smsService

func init() {
	SmsService = smsService{}
}

// Send 发送短信
// 结合适配器模式和工厂模式实现各短信服务商的调用
// 每增加一种短信服务商，按 Sms.SmsInterface 这个接口来对接即可
func (u smsService) Send(mobile string) (bool, error) {
	var smsClient Sms.SmsInterface
	switch setting.SmsSetting.SmsType {
	case "aliyun":
		smsClient = Sms.AliyunClient()
	default: // 默认是阿里云
		smsClient = Sms.AliyunClient()
	}
	return Sms.NewAdapter(smsClient).SendSms(mobile)
}

// Send 发送短信
// 结合适配器模式和工厂模式实现各短信服务商的调用
// 每增加一种短信服务商，按 Sms.SmsInterface 这个接口来对接即可
func (u smsService) Verify(mobile string, smsCode string) (bool, error) {
	var smsClient Sms.SmsInterface
	//switch setting.SmsSetting.SmsType {
	//case "aliyun":
	//	smsClient = Sms.AliyunClient()
	//default: // 默认是阿里云
	//	smsClient = Sms.AliyunClient()
	//}
	return Sms.NewAdapter(smsClient).VerifySms(mobile, smsCode)
}
